#pragma once

#include "TemplateParameterSubstitution.h"

#include "ParameterableElement.h"
#include "TemplateBinding.h"
#include "TemplateParameter.h"

namespace uml {

TemplateParameterSubstitution::TemplateParameterSubstitution(const QString& umlType)
    : Element(umlType) {}

void TemplateParameterSubstitution::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Element::fromJson(json, errorList);
    actual_ = JsonSerializable::create<ParameterableElement>(json.value("actual"), errorList);

    formal_ = JsonSerializable::create<TemplateParameter>(json.value("formal"), errorList);

    ownedActual_ = JsonSerializable::create<ParameterableElement>(json.value("ownedActual"), errorList);

    templateBinding_ = JsonSerializable::create<TemplateBinding>(json.value("templateBinding"), errorList);

}

void TemplateParameterSubstitution::toJson(QJsonObject& json) {
    Element::toJson(json);
    if (actual_) {
        QJsonObject actual_json;
        actual_->toJson(actual_json);
        json.insert("actual", actual_json);
    }
    if (formal_) {
        QJsonObject formal_json;
        formal_->toJson(formal_json);
        json.insert("formal", formal_json);
    }
    if (ownedActual_) {
        QJsonObject ownedActual_json;
        ownedActual_->toJson(ownedActual_json);
        json.insert("ownedActual", ownedActual_json);
    }
    if (templateBinding_) {
        QJsonObject templateBinding_json;
        templateBinding_->toJson(templateBinding_json);
        json.insert("templateBinding", templateBinding_json);
    }
}

/// <summary>
/// actual getter
/// The ParameterableElement that is the actual parameter for this
/// TemplateParameterSubstitution.
/// </summary>
shared_ptr<ParameterableElement> TemplateParameterSubstitution::actual() const {
    return actual_;
}

/// <summary>
/// actual setter
/// The ParameterableElement that is the actual parameter for this
/// TemplateParameterSubstitution.
/// </summary>
void TemplateParameterSubstitution::setActual(shared_ptr<ParameterableElement> value) {
    actual_ = value;
}

/// <summary>
/// formal getter
/// The formal TemplateParameter that is associated with this
/// TemplateParameterSubstitution.
/// </summary>
shared_ptr<TemplateParameter> TemplateParameterSubstitution::formal() const {
    return formal_;
}

/// <summary>
/// formal setter
/// The formal TemplateParameter that is associated with this
/// TemplateParameterSubstitution.
/// </summary>
void TemplateParameterSubstitution::setFormal(shared_ptr<TemplateParameter> value) {
    formal_ = value;
}

/// <summary>
/// ownedActual getter
/// The ParameterableElement that is owned by this TemplateParameterSubstitution as
/// its actual parameter.
/// </summary>
shared_ptr<ParameterableElement> TemplateParameterSubstitution::ownedActual() const {
    return ownedActual_;
}

/// <summary>
/// ownedActual setter
/// The ParameterableElement that is owned by this TemplateParameterSubstitution as
/// its actual parameter.
/// </summary>
void TemplateParameterSubstitution::setOwnedActual(shared_ptr<ParameterableElement> value) {
    ownedActual_ = value;
}

/// <summary>
/// templateBinding getter
/// The TemplateBinding that owns this TemplateParameterSubstitution.
/// </summary>
shared_ptr<TemplateBinding> TemplateParameterSubstitution::templateBinding() const {
    return templateBinding_;
}

/// <summary>
/// templateBinding setter
/// The TemplateBinding that owns this TemplateParameterSubstitution.
/// </summary>
void TemplateParameterSubstitution::setTemplateBinding(shared_ptr<TemplateBinding> value) {
    templateBinding_ = value;
}

} // namespace uml
